﻿using System;
using System.Windows;
namespace System.Windows {
	/// <summary>
	/// Presenter
	/// </summary>
	/// <typeparam name="TView">The type of the view.</typeparam>
	public abstract class Presenter<TView>
		where TView : IView {
		#region Fields
		private readonly TView view;
		#endregion
		#region Constructor
		/// <summary>
		/// Initializes a new instance of the <see cref="Presenter&lt;TView&gt;"/> class.
		/// </summary>
		/// <param name="view">The view.</param>
		public Presenter(TView view) {
			this.view = view;

			this.view.Loaded += (view_Loaded);
			this.view.Unloaded += (view_Unloaded);
		}

		
		#endregion
		#region Private
		private void view_Loaded(object sender, RoutedEventArgs e) {
			this.Refresh();
		}
		private void view_Unloaded(object sender, RoutedEventArgs e) {

		}
		#endregion
		#region Protected

		#endregion
		#region Public
		/// <summary>
		/// Refreshes the view.
		/// </summary>
		public virtual void Refresh() {

		}
		#endregion
		#region Property
		/// <summary>
		/// Gets the view.
		/// </summary>
		public TView View {
			get { 
				return view; 
			}
		}
		#endregion
	}

	/// <summary>
	/// Base Presenter
	/// </summary>
	public abstract class Presenter : Presenter<IView> {
		/// <summary>
		/// Initializes a new instance of the <see cref="Presenter"/> class.
		/// </summary>
		/// <param name="view">The view.</param>
		public Presenter(IView view)
			: base(view) {
		}
	}
	/// <summary>
	/// Presenter
	/// </summary>
	/// <typeparam name="TView">The type of the view.</typeparam>
	/// <typeparam name="TModel">The type of the model.</typeparam>
	public abstract class Presenter<TView, TModel> : Presenter<TView>
		where TView : IView
		where TModel : IModel {
		#region Fields
		private readonly TModel model;
		#endregion
		#region Constructor
		/// <summary>
		/// Initializes a new instance of the <see cref="Presenter&lt;TView, TModel&gt;"/> class.
		/// </summary>
		/// <param name="view">The view.</param>
		/// <param name="model">The model.</param>
		public Presenter(TView view, TModel model)
			: base(view) {
				this.model = model;

		}
		#endregion
		#region Property
		/// <summary>
		/// Gets the model.
		/// </summary>
		public TModel Model {
			get { return this.model; }
		}
		#endregion
	}
}
